package vigenere;

public class SMAC {
	
	public static void main(String[] args) {
		String text = "TXT: \"UEBERWEISUNG AN MEIKO JENSEN: EUR 100\"";
		
		boolean found = false;
		int key = 0;
		
		do{
			int s = encode(text, key);
			
			if(s == 226){
				found=true;
			}else{
				key++;
			}
			
		}while(found==false && key < 256);

		System.out.println("Key: "+key);
		
		String newText1 = "TXT: \"UEBERWEISUNG AN MEIKO JENSEN: EUR 1100\"";
		int newMac1 = encode(newText1, key);
		System.out.println(newText1+" MAC: "+newMac1);
		
		String newText2 = "TXT: \"UEBERWEISUNG AN RICO FLAEGEL: EUR 423\"";
		int newMac2 = encode(newText2, key);
		System.out.println(newText2+" MAC: "+newMac2);
		
		
	}
	
	public static int encode(String text, int iv){
		int s = iv;
		for(int i = 0; i< text.length(); i++){
			s = ( s+text.charAt(i) ) % 256;
		}
		return s;
	}

}
